package com.liaogui.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author liaogui
 * @date 2025/1/17 15:29
 */
@Slf4j
public class ThreadPoolDemo {
    public static void main(String[] args) {
        // 核心线程数 最大线程数 // 非核心线程数闲置时间 // 等待队列 // 拒绝策略
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(3, 4, 60, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(32), new ThreadPoolExecutor.CallerRunsPolicy());

        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                log.info("线程{}:启动成功", Thread.currentThread().getId());
            });
            threadPoolExecutor.execute(thread);
        }
    }
}
